Examples of Order Management Extensions for Order Headers

您所在的位置:网站首页 purchase order sales order Examples of Order Management Extensions for Order Headers

Examples of Order Management Extensions for Order Headers

2023-04-19 14:11| 来源: 网络整理| 查看: 265

Use these code examples to help you create Order Management Extensions that manipulate data on the sales order header.

Many of these examples test a value for the purchase order number on the order header. This test isolates the extension and prevents it from affecting other developers who might also be running test code. For details, see Overview of Creating Order Management Extensions.

1. Set the Billing Transaction Type According to Order Type import oracle.apps.scm.doo.common.extensions.ValidationException; import oracle.apps.scm.doo.common.extensions.Message; String orderTypeCode = header.getAttribute("TransactionTypeCode"); def billingTxnTypeId = null; //Message msg = new Message(Message.MessageType.WARNING, "Order Type: " + orderTypeCode); //throw new ValidationException(msg); //Case statement that tests the order type and calls function to get billing transaction type. switch (orderTypeCode) { case ["AUTO RETURN - SHIP", "AUTO RETURN - SHIP", "AUTO RETURN - MXT SHIP", "Mosoi_test"]: billingTxnTypeId = getBillingTxnTypeId("MOTO_INVOICE"); //msg = new Message(Message.MessageType.WARNING, "First Case " + billingTxnTypeId ); break; case ["UnreferencedRMA"]: billingTxnTypeId = getBillingTxnTypeId("Invoice"); //msg = new Message(Message.MessageType.WARNING, "Second Case " + billingTxnTypeId ); break; default: billingTxnTypeId = null; //msg = new Message(Message.MessageType.WARNING, "Default " + billingTxnTypeId ); break; } //throw new ValidationException(msg); //update all order lines with the Billing Transaction Type. def lines = header.getAttribute("Lines"); //get the lines row set while (lines.hasNext()) { //if there are more order lines def line = lines.next(); line.setAttribute("BillingTransactionTypeIdentifier", billingTxnTypeId); } //Function to get Billing Transaction Type Long getBillingTxnTypeId(String billingTxnTypeName) { def txnTypePVO = context.getViewObject("oracle.apps.financials.receivables.publicView.TransactionTypePVO"); //Create view criteria (where clause predicates) def vc = txnTypePVO.createViewCriteria(); def vcrow = vc.createViewCriteriaRow(); //Only return Billing Transaction Type for the common set that you must change. vcrow.setAttribute("Name", billingTxnTypeName); vcrow.setAttribute("SetName", "Common Set"); //Run the view object query to find a matching row. def rowset = txnTypePVO.findByViewCriteriaWithBindVars(vc, 1, new String[0], new Object[0]); //See if we have a matching row. def row = rowset.first(); Long txnTypeId = (Long) row.getAttribute("CustTrxTypeSeqId"); return txnTypeId; } 2. Add Attachment to Order Header import oracle.apps.scm.doo.common.extensions.ValidationException; import oracle.apps.scm.doo.common.extensions.Message; import oracle.apps.scm.doo.common.extensions.Attachment; import oracle.jbo.domain.BlobDomain; String poNumber = header.getAttribute("CustomerPONumber"); if (poNumber == null) return; if (!poNumber.startsWith("WriteAttachmentsHeaderOnEndSubmit_run_extension")) return; List < Message > messages = new ArrayList < Message > (); //messages.add(new Message( Message.MessageType.ERROR, "HeaderId: " + header.getAttribute("HeaderId"))); ////create header attachments //Create TEXT attachment Attachment newAttachment1 = new Attachment(); newAttachment1.setDatatypeCode("TEXT"); newAttachment1.setTitle("This is a text type title on submit"); newAttachment1.setText("this is some text"); newAttachment1.setDescription("this is some description"); header.createAttachment(newAttachment1); //Create URL attachment Attachment newAttachment2 = new Attachment(); newAttachment2.setDatatypeCode("WEB_PAGE"); newAttachment2.setTitle("This URL points to google server on submit"); newAttachment2.setUrl("http://www.google.com/"); newAttachment2.setDescription("Used for searching stuffs"); header.createAttachment(newAttachment2); //Create a file attachment Attachment newAttachment3 = new Attachment(); newAttachment3.setDatatypeCode("FILE"); newAttachment3.setTitle("file type title"); newAttachment3.setDescription("this file contains some random data on submit"); newAttachment3.setFileName("APITextFile.txt"); //newAttachment3.setFileContentType("application/text"); newAttachment3.setFileContentType("text/plain"); //newAttachment3.setFileContent(new BlobDomain("This is a test creation using Bytes".getBytes())); newAttachment3.setFileContent("This is a test for creation file from api using bytes".getBytes()); header.createAttachment(newAttachment3); /*delete all header attachments //messages.add(new Message( Message.MessageType.ERROR, "Delete all header attachments")); def attachments1 = header.getAttachments(); for (int i; i< attachments1.size(); ++i) { def attachment1 = attachments1[i]; //header.deleteAttachment(attachment1); }*/ ValidationException ex = new ValidationException(messages); throw ex; 3. Delete Attachment from Order Header import oracle.apps.scm.doo.common.extensions.ValidationException; import oracle.apps.scm.doo.common.extensions.Message; import oracle.apps.scm.doo.common.extensions.Attachment; import oracle.jbo.domain.BlobDomain; String poNumber = header.getAttribute("CustomerPONumber"); if (poNumber == null) return; if (!poNumber.startsWith("DeleteAttachmentsHeaderOnSubmit_run_extension")) return; //delete all header attachments //messages.add(new Message( Message.MessageType.ERROR, "Delete all header attachments")); def attachments1 = header.getAttachments(); for (int i; i < attachments1.size(); ++i) { //throw new ValidationException("An order with the Purchase Order ddddd Number " + attachments1 + " already exists."); def attachment1 = attachments1[i]; header.deleteAttachment(attachment1); } 4. Set Extensible Flexfield On Order Header

Set an attribute to the current date and time. Use an extensible flexfield on the order header.

import oracle.apps.scm.doo.common.extensions.ValidationException; def poNumber = header.getAttribute("CustomerPONumber"); //throw new ValidationException("An order with the Purchase Order Number " + poNumber + " already exists."); if (poNumber == null || !poNumber.startsWith("SetDateEffAttributeOnSubmit")) return; Date now = new Date(); //throw new ValidationException("An order with the Purchase Order Number " + now + " already exists."); def complianceDetails = header.getOrCreateContextRow("ComplianceDetails"); complianceDetails.setAttribute("compliancedatetime", now); 5. Set the Pricing Freeze Attributes on the Order Header String poNumber = header.getAttribute("CustomerPONumber"); if (poNumber == null) return; if (!poNumber.startsWith("WriteFreezeFlags_run_extension")) return; header.setAttribute("FreezePriceFlag", "N"); header.setAttribute("FreezeShippingChargeFlag", "N"); header.setAttribute("FreezeTaxFlag", "N"); 6. Set Extensible Flexfield Values for Hazardous Items

If the HazardousMaterialFlag attribute equals Y, then set value for attributes that use extensible flexfields on the order header and order lines.

import oracle.apps.scm.doo.common.extensions.ValidationException; def poNumber = header.getAttribute("CustomerPONumber"); if (poNumber == null) return; if (!poNumber.startsWith("SetEFFAttributeOnSave")) return; def lines = header.getAttribute("Lines"); while (lines.hasNext()) { def line = lines.next(); def inventoryItemId = line.getAttribute("ProductIdentifier"); def orgId = line.getAttribute("InventoryOrganizationIdentifier"); def item = getItem(inventoryItemId, orgId); String hazardous = item.getAttribute("HazardousMaterialFlag"); //throw new ValidationException("Item Hazardous Material Flag is " + hazardous); if ("Y".equals(hazardous)) { //get tow for fulfill line context PackShipInstruction def packShipInstruction = line.getOrCreateContextRow("PackShipInstruction"); packShipInstruction.setAttribute("shippinginstruction", "Hazardous Handling Required."); } } Date now = new Date(); def complianceDetails = header.getOrCreateContextRow("ComplianceDetails"); complianceDetails.setAttribute("compliancedatetime", now); complianceDetails.setAttribute("compliancereason", "This is a compliance reason."); Object getItem(Long itemId, Long orgId) { def itemPVO = context.getViewObject("oracle.apps.scm.productModel.items.publicView.ItemPVO"); def vc = itemPVO.createViewCriteria(); def vcrow = vc.createViewCriteriaRow(); vcrow.setAttribute("InventoryItemId", itemId); vcrow.setAttribute("OrganizationId", orgId); vc.add(vcrow); def rowset = itemPVO.findByViewCriteriaWithBindVars(vc, -1, new String[0], new String[0]); def item = rowset.first(); return item; } 7. Set Payment Term on Order Header

Set the default value to use for the payment term on the order header.

import oracle.apps.scm.doo.common.extensions.ValidationException; import oracle.apps.scm.doo.common.extensions.Message; List < Message > messages = new ArrayList < Message > (); def logger = context.getLogger(); def HeaderPayTerm = header.getAttribute("PaymentTerm"); def PName = header.getAttribute("BillToCustomerName"); def AId = header.getAttribute("BillToCustomerIdentifier"); def lines = header.getAttribute("Lines"); while (lines.hasNext()) { def line = lines.next(); def linePayTerm = line.getAttribute("PaymentTerm"); def linetransactioncode = line.getAttribute("TransactionCategoryCode") def partyId = getBillToPartyId(PName); def termId = gettermID(AId, partyId); def termName = gettermName(termId); if (HeaderPayTerm == null && linePayTerm == null && linetransactioncode != 'RETURN') { if (termName != null) header.setAttribute("PaymentTerm", termName.getAttribute("Name")); } } Object getBillToPartyId(String partyName) { def partyId; def logger = context.getLogger(); def custPVO = context.getViewObject("oracle.apps.scm.doo.workbench.publicViewEcsf.view.CustomerPVO"); def vc = custPVO.createViewCriteria(); def vcrow = vc.createViewCriteriaRow(); vcrow.setAttribute("PartyName", partyName); def rowset = custPVO.findByViewCriteria(vc, -1); def partyIdRowSet = rowset.first(); if (partyIdRowSet != null) partyId = partyIdRowSet.getAttribute("PartyId"); logger.logSevere("party id for Bill To customer", partyId); return partyId; } Object gettermID(Long AId, Long partyId) { def termId; def logger = context.getLogger(); def custProfilePVO = context.getViewObject("oracle.apps.financials.receivables.publicView.analytics.CustomerProfilePVO"); def vc1 = custProfilePVO.createViewCriteria(); def vcrow1 = vc1.createViewCriteriaRow(); vcrow1.setAttribute("CustAcctProfileCustAccountId", AId); vcrow1.setAttribute("CustFinProfileSiteUseId", null); vcrow1.setAttribute("CustAcctProfilePartyId", partyId); def rowset1 = custProfilePVO.findByViewCriteria(vc1, -1); def profile = rowset1.first(); if (profile != null) termId = profile.getAttribute("CustProfileStandardTerms"); logger.logSevere("Term Id from customer profile VO", termId); return termId; } Object gettermName(Long termID) { def raTermPVO = ontext.getViewObject("oracle.apps.financials.receivables.publicView.TrxPaymentTermPVO"); def vc2 = raTermPVO.createViewCriteria(); def vcrow2 = vc2.createViewCriteriaRow(); vcrow2.setAttribute("TermId", termID); def rowset2 = raTermPVO.findByViewCriteria(vc2, -1); def termName = rowset2.first(); return termName; } 8. Validate That Ship-to Site Belongs to Business Unit on Order Header import oracle.apps.scm.doo.common.extensions.ValidationException; def VARShipToPartySiteIdentifier = header.getAttribute("ShipToPartySiteIdentifier"); def VARBusinessUnitIdentifier = header.getAttribute("BusinessUnitIdentifier"); def ShipToPartySite = getShipTo(VARShipToPartySiteIdentifier); def RETShipToSetId = ShipToPartySite.getAttribute("SetId") def VARBusinesseUnitSetId = 0 //Test each combination of the business unit and assignment set. Use this SQL: //SELECT haotl.NAME , //haotl.organization_id, //fsa.SET_ID //FROM fusion.FND_SETID_ASSIGNMENTS fsa, //fusion.HR_ORGANIZATION_UNITS_F_TL haotl //WHERE reference_group_name LIKE 'HZ_CUSTOMER_ACCOUNT_SITE' //AND determinant_value = haotl.organization_id //AND haotl.NAME LIKE '&Business_Unit_Name%' //AND haotl.LANGUAGE = USERENV('LANG') // if (300000017871360. equals(VARBusinessUnitIdentifier)) { VARBusinesseUnitSetId = 300000000002582; } if ((VARBusinesseUnitSetId).equals(RETShipToSetId)) {} else { //You can modify this validation error to match your business needs. This example includes details about the setIDs. Throw new ValidationException("BU Set Id does not match Customer Ship to SET ID - BU Set ID is " + VARBusinesseUnitSetId + " Ship to Set ID is :" + RETShipToSetId) } Object getShipTo(Long ShipToSiteId) { def ShipToPVO = context.getViewObject("oracle.apps.hed.campusCommunity.shared.shoppingCart.publicModel.view.AccountSitePVO"); def vc = ShipToPVO.createViewCriteria(); def vcrow = vc.createViewCriteriaRow(); vcrow.setAttribute("PartySiteId", ShipToSiteId); def rowset = ShipToPVO.findByViewCriteria(vc, -1); def ShipTo = rowset.first(); return ShipTo; }

9. Prevent Duplicate Purchase Order Numbers on Order Header

Prevent Order Management from creating a duplicate of the purchase order number on the order header.

import oracle.apps.scm.doo.common.extensions.ValidationException; //get the customer PO number, order number, and the buying party id from the order header of the sales order you're saving. String customerPONumber = header.getAttribute("CustomerPONumber"); String buyingPartyIdentifier = header.getAttribute("BuyingPartyIdentifier"); String OrderNumber = header.getAttribute("OrderNumber"); //If the PO number is empty, then there's nothing to validate. if (customerPONumber == null) return; //Convert the PO number to upper case. customerPONumber = customerPONumber.toUpperCase() //Use the HeaderPVO to run a query according to customer PO number and sold to party's ID. //Use a view criteria to set where clause. def vo = context.getViewObject("oracle.apps.scm.doo.publicView.analytics.HeaderPVO"); def vc = vo.createViewCriteria(); def vcrow = vc.createViewCriteriaRow(); vcrow.setAttribute("CustomerPoNumber", customerPONumber); vcrow.setAttribute("SoldToPartyId", buyingPartyIdentifier); vc.add(vcrow); //Use a view criteria to find one row. Even if we find one row, we know that we already have an order with the same PO number and bill to site ID def rowset = vo.findByViewCriteria(vc, 1); if (rowset.hasNext()) { //We found a sales order for the bill to site and the order number. //Now test to see if we alrady saved this sales order or if this is a revision. def vcSameOrder = vo.createViewCriteria(); def vcSameOrderrow = vc.createViewCriteriaRow(); vcSameOrderrow.setAttribute("CustomerPoNumber", customerPONumber); vcSameOrderrow.setAttribute("SoldToPartyId", buyingPartyIdentifier); vcSameOrderrow.setAttribute("OrderNumber", OrderNumber); vcSameOrder.add(vcSameOrderrow); def rowsetSameOrder = vo.findByViewCriteria(vcSameOrder, 1); if (rowsetSameOrder.hasNext()) { //We found a sales order that has the same order number and PO number as the order that we're already working on. this is a valid case. The order found is a revision or a previously saved order. header.setAttribute("CustomerPONumber", customerPONumber); } else //We found a different sales order for a different order number. //Convert the customerPO number to upper case. { throw new ValidationException("An order with the Purchase Order Number for this Customer already exists " + customerPONumber + " already Exists"); } } else //We didn't find a sales order that has the same the bill to site id and po number, so we can save it. //Covert the customerPO number to upper case. { header.setAttribute("CustomerPONumber", customerPONumber); }



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3